﻿/*
	Class Description: a small example of using FPSPanel of MiniDebugger 
	library
	------------------------------------------------------------------------
	                          APACHE LICENSE
	------------------------------------------------------------------------
	Copyright 2010 Vu Thien Nguyen Phong
	
	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
	
*/
package  {
	import flash.display.Sprite;
	import flash.events.Event;
	import com.minidebugger.MiniDebugger;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	
	public class FPSPanelDemo extends Sprite {
		public function FPSPanelDemo() {
			addEventListener(Event.ADDED_TO_STAGE,init);
		}
		
		private function init(e:Event):void{
			removeEventListener(Event.ADDED_TO_STAGE,init);
			
			// entry point
			var ballHolder:Sprite = new Sprite();
			var fps:Sprite = new Sprite();
			
			addChild(ballHolder);
			addChild(fps);
			
			fps.addChild(MiniDebugger.getFPSPanel());
			
			// create 100 Ball movie clip every second and see its performance
			var timer:Timer = new Timer(1000);
			timer.addEventListener(TimerEvent.TIMER,function(e:Event):void{
				for(var i:int=0;i<1000;i++){
					var ball:Ball = new Ball();
					ball.x = Math.random()*stage.stageWidth;
					ball.y = Math.random()*stage.stageHeight;
					ball.scaleX = ball.scaleY = Math.random();
					ball.rotation = Math.random()*360;
					ballHolder.addChild(ball);
				}					   
								   });
			timer.start();
		}
	}
}
